package tryon

import (
	"fmt"
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/tryon/request"
	tryres "github.com/flipped-aurora/gin-vue-admin/server/model/tryon/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type TryOnApi struct{}

// Submit
// @Tags      TryOn
// @Summary   换装
// @Accept    application/json
// @Produce   application/json
// @Param     data body request.TryOnRequest true "换装参数"
// @Success   200 {object} response.Response{data=tryres.TryOnResponse,msg=string} "上传文件成功，返回换装结果图片"
// @Router    /tryOn/submit [post]
func (t *TryOnApi) Submit(c *gin.Context) {
	req := new(request.TryOnRequest)
	if err := c.ShouldBind(req); err != nil { // 这里改为 ShouldBind，支持表单参数绑定
		global.GVA_LOG.Error("参数绑定失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
		return
	}
	r, err := tryOnService.ChangeClothes(req)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("换装失败，原因：%s", err.Error()), c)
		return
	}
	response.OkWithData(tryres.TryOnResponse{ResultImage: r}, c)
}
